<cfparam name = "id" default="0">
<cfparam name = "start" default="1">
<cfparam name = "disp" default="50">
<cfparam name = "end" default="999">
<cfparam name = "sortby" default = "affiliateid">
<cfparam name = "sortorder" default = "ASC">
<cfparam name = "updateid" default = "0">
<cfparam name = "viewgroup" default = "All">
<cfparam name = "searchbox" default = "">
<cfparam name = "errormsg" default = "">
<cfparam name = "viewtype" default="0">
<cfparam name = "atype" default="0">
<cfparam name = "errormsg" default="">
<cfparam name = "companyname" default="">
<cfparam name = "firstname" default="Anonymous">
<cfparam name = "lastname" default="User">
<cfparam name = "email" default="">
<cfparam name = "confirm_email" default="">
<cfparam name = "address" default="">
<cfparam name = "address2" default="">
<cfparam name = "city" default="">
<cfparam name = "state" default="">
<cfparam name = "scountry" default="United States">
<cfparam name = "zip" default="">
<cfparam name = "phone" default="">
<cfparam name = "pword" default="">
<cfparam name = "password" default="">
<cfparam name = "confirmpassword" default="">
<cfparam name = "username" default="">
<cfparam name = "password" default="">
<cfparam name = "gender" default="0">
<cfparam name = "parentid" default="0">
<cfparam name = "joindate" default="#now()#">
<cfparam name = "confirmed" default="1">
<cfparam name = "timezone_offset" default="5,1">
<cfparam name = "formaction" default="Add">
<cfparam name = "notes" default="">
<cfparam name = "avatar" default="#request.absolutepath#images/avatars/no_pic.png">
<cfset showform = 1>
<cfif a IS 'Edit'>
  <cfset formaction = 'Edit'>
</cfif>

<cfif isdefined('form.lastname')>
  <cfset showform = 0>
  <cfif formaction IS 'Add'>
    <cfinclude template="../act/add.cfm">
  </cfif>
  <cfif formaction IS 'Edit'>
    <cfinclude template="../act/update.cfm">
  </cfif>
</cfif>
<cfif showform IS 1>
  <cfinvoke component="cfcs.account" method="gettypes" returnvariable="qtypes" />
  <cfinvoke component="cfcs.common.shared" method="getcountries" returnvariable="qcountries" />
  <cfif formaction IS 'Edit'>
    <cfinvoke component="cfcs.account" method="getuser" id="#id#" returnvariable="quser" />
    <cfloop query = "quser">
    <cfset atype=quser.atype>
    <cfset companyname=quser.companyname>
    <cfset firstname=quser.firstname>
    <cfset lastname=quser.lastname>
    <cfset email=quser.email>
    <cfset confirmed = quser.confirmed>
    <cfset address=quser.address>
    <cfset address2=quser.address2>
    <cfset city=quser.city>
    <cfset state=quser.state>
    <cfset scountry=quser.country>
    <cfset zip=quser.zip>
    <cfset phone=quser.phone>
    <cfset username=quser.username>
    <cfset pword=quser.pword>
    <cfset gender=quser.gender>
    <cfset parentid=quser.parentid>
    <cfset timezone_offset=quser.timezone_offset>
    <cfset joindate=quser.joindate>
    <cfset notes=quser.notes>
    <cfset avatar=quser.avatar>
    </cfloop>
  </cfif>
  <cfinvoke component="cfcs.account" method="getparent" parentid="#parentid#" returnvariable="qparent" />
  <cfoutput>
  <table width=100% border=0 align="center" cellPadding="0" cellSpacing="0">
    <tr>
      <td width="100%" valign="top"><form name="editaccount" id="editaccount" action="index.cfm?c=accounts&a=#formaction#" method="post">
          <table width="100%" cellpadding="4" cellspacing="0">
            <tr>
              <td id="columnheaders" colspan="2">#formaction# User Account </td>
            </tr>
            <cfif len(trim(errormsg)) GT 0>
            <tr>
              <td colspan="2" align="left" valign="top" class="form_td">
                  <div style="color: ##FF0000; font-weight: bold;">
                  #errormsg#
                  </div>
				</td>
            </tr>
			</cfif>
            <tr>
              <td align="left" valign="top" class="form_td">#request.lang.accounts.addedit.label1#:</td>
              <td align="left" valign="top" class="form_td"><cfif len(trim(joindate)) GT 0>
                  <cfset sdate = joindate>
                  <cfelse>
                  <cfset sdate = now()>
                </cfif>
                <cfset thisyear = now()>
                <cfset thisyear = dateformat(thisyear, "yyyy")>
                <cfset syear = dateformat(sdate, "yyyy")>
                <cfset smonth = dateformat(sdate, "m")>
              <cfset sday = dateformat(sdate, "d")></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label2#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="firstName" size="25" id="firstName" value="#firstname#">
                <span id="required">*</span></td>
            </tr>
            <tr>
              <td valign="top" class="form_td">#request.lang.accounts.addedit.label3#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="lastName" value="#lastName#" size="30">
                <span id="required">*</span></td>
            </tr>
            <tr>
              <td  class="form_td" valign="middle" >#request.lang.accounts.addedit.label4#:</td>
              <td valign="top"  class="form_td"><input type="text" name="username" id="username" value="#username#" onchange="ColdFusion.navigate('#request.absolutepath#dialogs/accounts/checkavailable.cfm?purl='+document.getElementById('username').value, 'checkit');" />
                <span id="required">*</span> <a href = "javascript: ColdFusion.navigate('#request.absolutepath#dialogs/accounts/checkavailable.cfm?purl='+document.getElementById('username').value, 'checkit');">#request.lang.accounts.addedit.checkit#</a>
                <cfdiv id="checkit"></cfdiv></td>
            </tr>
            <tr>
              <td  class="form_td" valign="middle" >
                <cfif formaction IS 'Edit'>
                  #request.lang.accounts.addedit.label5_2#
                <cfelse>
	              #request.lang.accounts.addedit.label5#
                </cfif>
                :</td>
              <td valign="top"  class="form_td"><cfif formaction IS 'Edit'>
                  <input type="checkbox" name="changepass" id="changepass" />
                  #request.lang.accounts.addedit.resetpw#:<br />
                </cfif>
                <cfset dpass = password>
                <cfif formaction IS 'Edit'>
                  <cftry>
                    <cfinvoke component="cfcs.common.encryption" method="decryptstring" encstring="#pword#" returnvariable="dpass">
                    <cfcatch type="any">
                      <cfset dpass = '<div style="color: red;">#request.lang.accounts.addedit.corruptpw#'>
                    </cfcatch>
                  </cftry>
                </cfif>
                <input type="text" name="password" id="password" value="#dpass#" />
                <cfif formaction IS 'Add'>
                  <span id="required">*</span>
                </cfif>
              </td>
            </tr>
            <tr>
              <td valign="top" class="form_td">#request.lang.accounts.addedit.label6#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="email" size="30" value="#email#">
                <span id="required">*</span> <br></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label7#:</td>
              <td align="left" valign="top" class="form_td"><select name="confirmed">
                  <option value="0" <cfif confirmed IS 0>selected="selected"</cfif>>No</option>
                  <option value="1" <cfif confirmed IS 1>selected="selected"</cfif>>Yes</option>
                </select>
              </td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label8#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="companyname" size="25" id="company" value="#companyname#" /></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label9#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="phone" size="25" value="#phone#"></td>
            </tr>
            <tr>
              <td valign="top" class="form_td">#request.lang.accounts.addedit.label10#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="address" size="30" value="#address#">
                <br>
                <input type="text" name="address2" size="30" value="#address2#"></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label11#:</td>
              <td align="left" valign="top" class="form_td"><input type="text" name="city" size="25" value="#city#"></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label12#:</td>
              <td align="left" valign="top"  class="form_td"><select name = "scountry" id="scountry" onchange="ColdFusion.navigate('#request.absolutepath#dialogs/statebox.cfm?country='+this.value+'&selectedstate=#state#', 'statediv');">
                  <cfloop query = "qcountries">
                  <option <cfif #qcountries.country# IS #scountry#>SELECTED</cfif> value="#qcountries.country#">#qcountries.country#</option>
                  </cfloop>
                </select></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label13#:</td>
              <td align="left" valign="top" class="form_td"><cfset selectedstate = state>
                <cfdiv id="statediv">
                <cfinclude template = "#request.absolutepath#dialogs/statebox.cfm">
                </cfdiv></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td">#request.lang.accounts.addedit.label14#:</td>
              <td align="left" valign="top"  class="form_td"><input type="text" name="zip" size="15" value="#zip#"></td>
            </tr>
            <tr>
              <td valign="middle" class="form_td" >#request.lang.accounts.addedit.label15#:</td>
              <td class="form_td" valign="top"><cfinvoke component="cfcs.common.shared" method="timezonedropdown" selected="#timezone_offset#"></td>
            </tr>
            <tr>
              <td valign="top"  class="form_td" >#request.lang.accounts.addedit.label16#:</td>
              <td valign="top"  class="form_td"><input type = "hidden" value="#parentid#" name="oldparent" />
                <input name="parentid" type="text" size="15" value="#parentid#" id="parentid" />
                <cfif qparent.recordCount GT 0>
                  - <span id="parentname">#qparent.FirstName# #qparent.LastName#</span>
                  <cfelse>
                  <span id="parentname">#request.lang.accounts.addedit.noreferral#</span>
                </cfif>
                <a href="javascript: userselect();">#request.lang.accounts.addedit.selectlink#</a></td>
            </tr>
            <tr>
              <td valign="top"  class="form_td" >#request.lang.accounts.addedit.label17#:</td>
              <td valign="top"  class="form_td"><textarea name="notes" id="notes" cols="65" rows="10">#notes#</textarea></td>
            </tr>
            <tr>
              <td valign="middle"  class="form_td" >#request.lang.accounts.addedit.label18#:<br />
              </td>
              <td valign="top"  class="form_td"><img src="#avatar#" name="avatarimg" border="0" align="absmiddle" id="avatarimg" style="max-width: 125px;">
                <input type = "hidden" name="avatar" id="avatar" value="#avatar#" />
                <a href = "javascript: avatarselect();">#request.lang.accounts.addedit.selectlink2#</a> </td>
            </tr>
            <tr>
              <td  class="form_td" valign="middle" ></td>
              <td valign="top"  class="form_td"><input type="hidden" name="gender" value="#gender#">
                <input type="hidden" name="id" value="#id#">
                <input type="hidden" name="disp" value="#disp#">
                <input type="hidden" name="start" value="#start#">
                <input type="hidden" name="searchbox" value="#searchbox#">
                <input type="hidden" name="sortby" value="#sortby#">
                <input type="hidden" name="sortorder" value="#sortorder#">
                <input type="hidden" name="viewtype" value="#viewtype#" />
                <input type="submit" name="abutton" id="abutton" value="#request.lang.accounts.addedit.savebutton#"></td>
            </tr>
          </table>
        </form></td>
    </tr>
  </table>
  </cfoutput>
  <cfinclude template="../dialogs/dialogdivs.cfm">
</cfif>
